package com.iwomy.envpro.platform.controller;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.iwomy.envpro.common.core.util.R;
import com.iwomy.envpro.common.log.annotation.SysLog;
import com.iwomy.envpro.platform.entity.AirOrderRecipientEntity;
import com.iwomy.envpro.platform.service.AirOrderRecipientService;
import org.springframework.security.access.prepost.PreAuthorize;
import com.iwomy.envpro.common.excel.annotation.ResponseExcel;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 订单收件人
 *
 * @author pig
 * @date 2023-08-29 16:18:14
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/airOrderRecipient" )
@Tag(description = "airOrderRecipient" , name = "订单收件人管理" )
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class AirOrderRecipientController {

    private final  AirOrderRecipientService airOrderRecipientService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param airOrderRecipient 订单收件人
     * @return
     */
    @Operation(summary = "分页查询" , description = "分页查询" )
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('platform_airOrderRecipient_view')" )
    public R getAirOrderRecipientPage(@ParameterObject Page page,@ParameterObject AirOrderRecipientEntity airOrderRecipient) {
        LambdaQueryWrapper<AirOrderRecipientEntity> wrapper = Wrappers.lambdaQuery(airOrderRecipient);
        return R.ok(airOrderRecipientService.page(page, wrapper));
    }


    /**
     * 通过id查询订单收件人
     * @param id id
     * @return R
     */
    @Operation(summary = "通过id查询" , description = "通过id查询" )
    @GetMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('platform_airOrderRecipient_view')" )
    public R getById(@PathVariable("id" ) Long id) {
        return R.ok(airOrderRecipientService.getById(id));
    }

    /**
     * 新增订单收件人
     * @param airOrderRecipient 订单收件人
     * @return R
     */
    @Operation(summary = "新增订单收件人" , description = "新增订单收件人" )
    @SysLog("新增订单收件人" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('platform_airOrderRecipient_add')" )
    public R save(@RequestBody AirOrderRecipientEntity airOrderRecipient) {
        return R.ok(airOrderRecipientService.save(airOrderRecipient));
    }

    /**
     * 修改订单收件人
     * @param airOrderRecipient 订单收件人
     * @return R
     */
    @Operation(summary = "修改订单收件人" , description = "修改订单收件人" )
    @SysLog("修改订单收件人" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('platform_airOrderRecipient_edit')" )
    public R updateById(@RequestBody AirOrderRecipientEntity airOrderRecipient) {
        return R.ok(airOrderRecipientService.updateById(airOrderRecipient));
    }

    /**
     * 通过id删除订单收件人
     * @param ids id列表
     * @return R
     */
    @Operation(summary = "通过id删除订单收件人" , description = "通过id删除订单收件人" )
    @SysLog("通过id删除订单收件人" )
    @DeleteMapping
    @PreAuthorize("@pms.hasPermission('platform_airOrderRecipient_del')" )
    public R removeById(@RequestBody Long[] ids) {
        return R.ok(airOrderRecipientService.removeBatchByIds(CollUtil.toList(ids)));
    }


    /**
     * 导出excel 表格
     * @param airOrderRecipient 查询条件
     * @return excel 文件流
     */
    @ResponseExcel
    @GetMapping("/export")
    @PreAuthorize("@pms.hasPermission('platform_airOrderRecipient_export')" )
    public List<AirOrderRecipientEntity> export(AirOrderRecipientEntity airOrderRecipient) {
        return airOrderRecipientService.list(Wrappers.query(airOrderRecipient));
    }
}